<{include file="Public/top.html" }>
	</head>
	<body>
		<div id="warpper">
            <div class="content">
                <div class="location">用户操作</div>
                <!-- 子导航 -->
                <{include file="./nav.html" }>

                <form action="<{u(pointDo)}>" method="post" class="ui-form" id="addManagerForm">
                <div class="filedSet">
                    <div class="topic">用户信息</div>
                    <div class="form-box border0 border-box">
                            <div class="ui-form-item" style="height:175px;">
                                <label class="ui-label">用户ID：</label>
                                <textarea class="ui-textarea" id="uid" name="uid" placeholder="多个用户使用“,”分割"></textarea>
                                <br />
                                <label class="ui-label" style="padding-left:120px; width:70px;">全员发送</label>
                                <input id="allUser" type="checkbox" value="1" name="all"/>
                            </div>
                            <div class="ui-form-item">
                                <label class="ui-label">标 题：</label>
                                <input type="text" class="ui-text" name="title" id="title" required/>
                            </div>
                            <div class="ui-form-item" style="height:140px;">
                                <label class="ui-label">用户通知：</label>
                                <textarea class="ui-textarea" name="msg" placeholder="因xxxxx,给您发放xxx积分" id="msg" required></textarea>
                            </div>
                            <div class="ui-form-item">
                                <label class="ui-label">增加积分：</label>
                                <input type="text" id="pointAdd" name="pointAdd" class="ui-text" value="" required/>
                            </div>
                            <div class="ui-form-item">
                                <label class="ui-label">扣除积分：</label>
                                <input type="text" id="pointReduce" name="pointReduce" class="ui-text" value="" required/>
                            </div>
                            <div class="ui-form-item">
                                <label class="ui-label">操作原因：</label>
                                <input name="reason" type="text" class="ui-text" style="width:585px;" id="reason" required/>
                            </div>

                    </div>
                </div>
                <div class="integral_btn-group">
                    <input type="button" value="提交" id="btn" class="ui-button"/>
                </div>
                </form>
            </div>
		</div>

        <div style="display:none;width: 100%;height: 100%;overflow:hidden; background:rgba(0,0,0,.7); position:absolute; top:0; z-index:999999;" id="cover">
            <input style="margin:20% auto;border: none;width:100%;height:10rem;text-align: center; " id="tips" type="text" value="" />
        </div>

        <{include file="Public/foot.html" }>
		<script>
            var flag = true;
			$(function(){
                $('#pointAdd').on('change',function(){
                    if($('#pointAdd').val().length>0){
                        $('#pointReduce').val('').attr('required',false)
                    }
                });
                $('#pointReduce').on('change',function(){
                    if($('#pointReduce').val().length>0){
                        $('#pointAdd').val('').attr('required',false)
                    }
                });
			});


            $('#allUser').on('ifChecked',function(){
                $('#uid').attr('disabled',true);
                $('#pointReduce').attr('disabled',true);

            }).on('ifUnchecked',function(){
                $('#uid').attr('disabled',false);
                $('#pointReduce').attr('disabled',false);
            });
//
            $("#btn").on('click',function(){
                if(flag){
                    if(!$("#uid").val() && !$("input[name=all]:checked").val()){
                        layer.msg("请输入用户ID或选择全员发送");
                        return false;
                    }
                    if(!$("#title").val()){
                        layer.msg("请输入标题");
                        return false;
                    }
                    if(!$("#msg").val()){
                        layer.msg("请输入通知内容");
                        return false;
                    }
                    if(!$("#pointAdd").val() && !$("#pointReduce").val()){
                        layer.msg("请输入发送积分");
                        return false;
                    }
                    if(!$("#reason").val()){
                        layer.msg("请输入操作原因");
                        return false;
                    }
                    flag = false;
                    deal(1);
                }
            });

            $("#cover").on('click',function(){
               $("#cover").css("display",'none');
            });

            function deal(index){
                var param = $("#addManagerForm").serialize();
                param = param+"&index="+index;
                $.post("<{U('pointDo')}>",param,function(res){
                    if(res.status == 0 ){
                        layer.msg(res.msg);
                        flag = true;
                    } else if(res.status == 1){
                        $("#cover").css("display","none");
                        layer.msg(res.msg);
                        flag = true;
                    } else if(res.status == 2){
                        $("#tips").val(res.msg);
                        $("#cover").css("display","block");
                        index +=1;
                        deal(index);
                    }
                });
            }

		</script>
	</body>
</html>
